import { z } from 'zod';

export const shopFormSchema = z.object({
  username: z
    .string()
    .min(2, { message: '用户名至少2个字符' })
    .max(50, { message: '用户名最多50个字符' }),
  name: z
    .string()
    .min(2, { message: '昵称至少2个字符' })
    .max(50, { message: '昵称最多50个字符' }),
  email: z.string().email({ message: '邮箱格式不正确' }),
  shopName: z
    .string()
    .min(2, { message: '商铺名称至少2个字符' })
    .max(50, { message: '商铺名称最多50个字符' }),
  contactPhone: z
    .string()
    .min(2, { message: '联系电话至少2个字符' })
    .max(50, { message: '联系电话最多50个字符' }),
  address: z
    .object(
      {
        address: z.string(),
        longitude: z.number(),
        latitude: z.number(),
      },
      { message: '请选择正确地址' },
    )
    .nullable(),
  password: z
    .string()
    .min(2, { message: '密码至少2个字符' })
    .max(50, { message: '密码最多50个字符' }),
  confirmPassword: z
    .string()
    .min(2, { message: '密码至少2个字符' })
    .max(50, { message: '密码最多50个字符' }),
});

export const shopInfoSchema = z.object({
  name: z
    .string()
    .min(2, { message: '昵称至少2个字符' })
    .max(50, { message: '昵称最多50个字符' }),
  contactPhone: z
    .string()
    .min(2, { message: '联系电话至少2个字符' })
    .max(50, { message: '联系电话最多50个字符' }),
  address: z.object(
    {
      address: z.string(),
      longitude: z.number(),
      latitude: z.number(),
    },
    { message: '请选择正确地址' },
  ),
  description: z.string().max(100, { message: '描述最多100个字符' }),
  deliveryMinPrice: z
    .string()
    .refine(
      (value) => {
        return !Number.isNaN(value);
      },
      { message: '最小配送价必须为数字' },
    )
    .refine((val) => Number(val) >= 0, { message: '最小配送价必须大于等于0' }),
  startTime: z.string(),
  endTime: z.string(),
});
